package view;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

import model.Admin;
import model.Course;
import model.Grades;
import model.Student;
import model.Teacher;

public class LoginView {
	//定义存储集合
	public final static List<Admin> AdminList = new ArrayList<>();
	public final static List<Teacher> TeacherList = new ArrayList<>();
	public final static List<Student> StudentList = new ArrayList<>();
	public final static List<Course> CourseList = new ArrayList<>();
	public final static List<Grades> GradesList = new ArrayList<>();
	//引入输入类
	Scanner input = new Scanner(System.in);

	public LoginView() {
		//管理员添加
		Admin admin = new Admin("A001","李四","123");
		AdminList.add(admin);
		//教师添加
		Teacher teacher = new Teacher("T001","张三","123");
		TeacherList.add(teacher);
		//课程添加
		Course course = new Course("C001","c语言",20,0,"T001");
		CourseList.add(course);
		//学生添加
		Student student = new Student("T001","钱六","123");
		StudentList.add(student);
	}
	
	
	//登录主界面
	public void login(){
		clear();
	      System.out.println("教务系统");
	      System.out.println("1、学生登录");
	      System.out.println("2、教师登录");
	      System.out.println("3、管理员登录");
	      System.out.println("0、退出系统");
	      System.out.println("#############################################");
	      System.out.println("请输入序号，选择操作!");
	      String x = input.next();
	      if(x.equals("0")) {
	    	  //退出系统
		      System.out.println("退出成功!");
	    	  return;
	      }else {
	    	  loginChild(x);
	      }
	}
	
	//登录子界面
	public void loginChild(String x) {
		clear();
		 System.out.println("请输入账号:");
	      String account = input.next();
	     System.out.println("请输入密码:");
	      String password = input.next();
	     if(x.equals("1")) {
	    	  //学生登录
	    	 Student student = selectStudentOne(account);
	    	  //返回值为空证明账号不存在
	    	  if(student == null) {
			      System.out.println("账户不存在");
			      return;
	    	  }
	    	  if(student.getPassword().equals(password)) {
	    		  //账号密码正确界面跳转
	    		  StudentView(account);
	    	  }else {
			      System.out.println("账户或密码错误");
			      //重新登录
			      loginChild(x);
	    	  }
	      }else if(x.equals("2")) {
	    	  //教师登录
	    	  Teacher teacher = selectTeacherOne(account);
	    	  //返回值为空证明账号不存在
	    	  if(teacher == null) {
			      System.out.println("账户不存在");
			      return;
	    	  }
	    	  if(teacher.getPassword().equals(password)) {
	    		  //账号密码正确界面跳转
	    		  TeacherView(teacher.getTeacherId());
	    	  }else {
			      System.out.println("账户或密码错误");
			      //重新登录
			      loginChild(x);
	    	  }
	      }else if(x.equals("3")) {
	    	  //管理员登录
	    	  Admin admin = selectAdminOne(account);
	    	  //返回值为空证明账号不存在
	    	  if(admin == null) {
			      System.out.println("账户不存在");
			      return;
	    	  }
	    	  if(admin.getPassword().equals(password)) {
	    		  //账号密码正确界面跳转
	    		  AdminView();
	    	  }else {
			      System.out.println("账户或密码错误");
			      //重新登录
			      loginChild(x);
	    	  }
	      }else {
		      System.out.println("请输入正确指令");
		      login();   
	}
	}

	//管理员主界面
	public void AdminView() {
		clear();
	      System.out.println("1、学生管理");
	      System.out.println("2、教师管理");
	      System.out.println("3、管理员管理");
	      System.out.println("4、课程管理");
	      System.out.println("0、退出登录");
	      System.out.println("#############################################");
	      System.out.println("请输入序号，选择操作!");
	      String x = input.next();
	      if(x.equals("1")) {
	    	  //学生管理
	    	  StudentManage();
	      }else if(x.equals("2")) {
	    	  //课程教师管理
	    	  TeacherManage();
	      }else if(x.equals("3")) {
	    	  //管理员管理
	    	  AdminManage();
	      }else if(x.equals("4")) {
	    	  // 课程管理
	    	  CourseManage();
	      }else if(x.equals("0")) {
	    	  //回到主界面
	    	  login();
	      }else {
	    	  System.out.println("请输入正确指令");
	    	  AdminView();
	      }
	}
	
	//学生管理界面
	public void StudentManage(){
		  System.out.println("1、添加学生");
	      System.out.println("2、删除学生");
	      System.out.println("3、修改学生信息");
	      System.out.println("4、查询学生信息");
	      System.out.println("0、返回");
	      System.out.println("#############################################");
	      System.out.println("请输入序号，选择操作!");
	      String x = input.next();
	      if(x.equals("1")) {
	    	  //添加学生
	    	  StudentAdd();
	      }else if(x.equals("2")) {
	    	  //删除学生
	    	  StudentDeleted();
	      }else if(x.equals("3")) {
	    	  //修改学生信息
	    	  StudentUpdate();
	      }else if(x.equals("4")) {
	    	  // 查询学生
	    	  StudentSelectAll();
	      }else if(x.equals("0")) {
	    	  //回到主界面
	    	  AdminView();
	      }else {
	    	  System.out.println("请输入正确指令");
	    	  StudentManage();
	      }
	}
	
	//教师管理界面
	public void TeacherManage(){
		  System.out.println("1、添加教师");
	      System.out.println("2、删除教师");
	      System.out.println("3、修改教师信息");
	      System.out.println("4、查询教师信息");
	      System.out.println("0、返回");
	      System.out.println("#############################################");
	      System.out.println("请输入序号，选择操作!");
	      String x = input.next();
	      if(x.equals("1")) {
	    	  //添加教师
	    	  TeacherAdd();
	      }else if(x.equals("2")) {
	    	  //删除教师
	    	  TeacherDeleted();
	      }else if(x.equals("3")) {
	    	  //修改教师
	    	  TeacherUpdate();
	      }else if(x.equals("4")) {
	    	  // 查看教师
	    	  TeacherSelectAll();
	      }else if(x.equals("0")) {
	    	  //回到主界面
	    	  AdminView();
	      }else {
	    	  System.out.println("请输入正确指令");
	    	  TeacherManage();
	      }
	
	}
	
	//管理员管理界面
	public void AdminManage(){

		  System.out.println("1、添加管理员");
	      System.out.println("2、删除管理员");
	      System.out.println("3、修改管理员信息");
	      System.out.println("4、查询管理员信息");
	      System.out.println("0、返回");
	      System.out.println("#############################################");
	      System.out.println("请输入序号，选择操作!");
	      String x = input.next();
	      if(x.equals("1")) {
	    	  //添加管理员
	    	  AdminAdd();
	      }else if(x.equals("2")) {
	    	  //删除管理员管理
	    	  AdminDeleted();
	      }else if(x.equals("3")) {
	    	  //修改管理员
	    	  AdminUpdate();
	      }else if(x.equals("4")) {
	    	  // 查询管理员
	    	  AdminSelectAll();
	      }else if(x.equals("0")) {
	    	  //回到主界面
	    	  AdminView();
	      }else {
	    	  System.out.println("请输入正确指令");
	    	  AdminManage();
	      }
	
	}
	
	//课程管理界面
	public void CourseManage(){
		  System.out.println("1、添加课程");
	      System.out.println("2、删除课程");
	      System.out.println("3、修改课程信息");
	      System.out.println("4、查询课程信息");
	      System.out.println("0、返回");
	      System.out.println("#############################################");
	      System.out.println("请输入序号，选择操作!");
	      String x = input.next();
	      if(x.equals("1")) {
	    	  CourseAdd();
	      }else if(x.equals("2")) {
	    	  CourseDeleted();
	      }else if(x.equals("3")) {
	    	  CourseUpdate();
	      }else if(x.equals("4")) {
	    	  CourseSelectAll();
	      }else if(x.equals("0")) {
	    	  //回到主界面
	    	  AdminView();
	      }else {
	    	  System.out.println("请输入正确指令");
	    	  CourseManage();
	      }
	}
	
	
	//教师主界面
	public void TeacherView(String teacherId) {
		clear();
		  System.out.println("1、课程查看");
	      System.out.println("2、课程学生查看");
	      System.out.println("3、成绩录入/修改管理");
	      System.out.println("4、修改密码");
	      System.out.println("0、退出登录");
	      System.out.println("#############################################");
	      System.out.println("请输入序号，选择操作!");
	      String x = input.next();
	      if(x.equals("1")) {
	    	  TeacherCourseAll(teacherId);
	      }else if(x.equals("2")) {
	    	  TeacherStudentAll(teacherId);
	      }else if(x.equals("3")) {
	    	GradesInput(teacherId);
	      }else if(x.equals("4")) {
	    	 TeacherPasswordUpadate(teacherId);
	      }else if(x.equals("0")) {
	    	  //回到主界面
	    	  login();
	      }else {
	    	  System.out.println("请输入正确指令");
	    	  TeacherView(teacherId);
	      }
	}
	
	//教师课程查看接口
	public void TeacherCourseAll(String teacherId) {
		int j= 1;
		for(int i=0;i<CourseList.size();i++) {
			if(CourseList.get(i).getTeacherId().equals(teacherId)) {
				System.out.println("序号          课程编号           课程名称            任课老师        课程人数              报名人数");
				System.out.println(j  + "     " +CourseList.get(i).getCourseId() + "     " + CourseList.get(i).getCourseName() + "     " + selectTeacherOne(CourseList.get(i).getTeacherId()).getName() + "         "  + CourseList.get(i).getNumber() + "         "  + CourseList.get(i).getFillNumber());
			
			}
		}
		TeacherView(teacherId);
	}
	//教师课程学生查看
	public void TeacherStudentAll(String teacherId) {
		System.out.println("请输入课程编号:");
		String courseId = input.next();
		 Course course1 = SelectCourseOne(courseId);
		 if(course1 == null) {
			 System.out.println("课程编号不存在!");
			 TeacherStudentAll(teacherId);
		 }
			for(int i=0;i<GradesList.size();i++) {
				if(GradesList.get(i).getCourseId().equals(courseId)) {
					System.out.println(course1.getCourseName() + "学生如下:");
					System.out.println(selectStudentOne(GradesList.get(i).getNoId()).getName());
				}
			}
			TeacherView(teacherId);
	}

	//成绩录入GradesList
	public void GradesInput(String teacherId){
		System.out.println("请输入课程号:");
		String CourseId = input.next();
		Course course = selectCourseOne(CourseId);
		if(course == null) {
			System.out.println("课程号不存在！");
		}
		//判断课程是否是自己的
		if(course.getTeacherId() != teacherId) {
			System.out.println("该课程不是您的课程！");
		}
		System.out.println("请输入学生学号:");
		String studentId = input.next();
		Grades grades = selectGradesOne(studentId,CourseId);
		//判断学生是否是自己的
		if(grades == null) {
			System.out.println("该课程没有此学生！");
		}
		//打分
		System.out.println("请输入成绩:");
		Double grades1 = input.nextDouble();
		selectGradesUpdate(studentId,CourseId,grades1);
		TeacherView(teacherId);
	}
	
	//添加更改成绩接口
	public void selectGradesUpdate(String id,String courseId,Double grades) {
		for(int i =0; i<GradesList.size();i++) {
			if(GradesList.get(i).getCourseId().equals(courseId)&&GradesList.get(i).getNoId().equals(id)) {
				GradesList.get(i).setGrades(grades);
				System.out.println("成绩录入成功！");
			}
		}
	}

	//教师修改密码接口
	public void TeacherPasswordUpadate(String teacherId) {
		System.out.println("请输入旧密码:");
		String oldPassword = input.next();
		Teacher teacher1 = selectTeacherOne(teacherId);
		if(teacher1 == null) {
			System.out.println("教师编号不存在！");
			TeacherPasswordUpadate(teacherId);
		}
		if(teacher1.getPassword().equals(oldPassword)) {
			System.out.println("旧密码错误！");
			TeacherPasswordUpadate(teacherId);
		}
		System.out.println("请输入新密码:");
		String newPassword = input.next();
		System.out.println("请输入新密码:");
		String newPassword2 = input.next();
		if(newPassword.equals(newPassword2)) {
			for(int i=0;i<TeacherList.size();i++) {
				if(TeacherList.get(i).getTeacherId().equals(teacherId)) {
					TeacherList.get(i).setPassword(newPassword);
					System.out.println("密码修改成功!");
					TeacherView(teacherId);
				}
			}
		}else {
			System.out.println("两次密码输入不一致！");
			TeacherPasswordUpadate(teacherId);
		}
		
	}
	
	//学生主界面
	public void StudentView(String studentId) {
		clear();
		  System.out.println("1、选课");
		  System.out.println("2、课程查看");
	      System.out.println("3、成绩查询");
	      System.out.println("4、修改密码");
	      System.out.println("0、退出登录");
	      System.out.println("#############################################");
	      System.out.println("请输入序号，选择操作!");
	      String x = input.next();
	      if(x.equals("1")) {
	    	  //选课
	    	  CourseSelection(studentId);
	    	  StudentView(studentId);
	      }else if(x.equals("2")) {
	    	  //课程查看 
	    	  StudentCourseSelect1(studentId);
	      }else if(x.equals("3")) {
	    	  //成绩查询
	    	  StudentGradesSelect1(studentId);
	      }else if(x.equals("4")) {
	    	  // 修改密码
	    	  StudentPasswordUpadate(studentId);
	      }else if(x.equals("0")) {
	    	  //回到主界面
	    	  login();
	      }else {
	    	  System.out.println("请输入正确指令");
	    	  StudentView(studentId);
	      }
	}
	
	//学生选课
	public void CourseSelection(String studentId) {
		for(int i=0;i<CourseList.size();i++) {
			System.out.println("序号          课程编号           课程名称            任课老师        课程人数              报名人数");
			System.out.println(i+1  + "     " +CourseList.get(i).getCourseId() + "     " + CourseList.get(i).getCourseName() + "     " + selectTeacherOne(CourseList.get(i).getTeacherId()).getName() + "         "  + CourseList.get(i).getNumber() + "         "  + CourseList.get(i).getFillNumber());
		}
		System.out.println("请输入课程编号:");
		String courseId = input.next();
		//判断课程号是否存在
		Course course = selectCourseOne(courseId);
		if(course == null) {
			System.out.println("该课程号不存在！");
			CourseSelection(studentId);
		}
		//判断是否选过
		for(int i=0;i<GradesList.size();i++) {
			if(GradesList.get(i).getNoId().equals(studentId)&&GradesList.get(i).getCourseId().equals(courseId)) {
				System.out.println("该课程已选过！");
				CourseSelection(studentId);
			}
		}
		//判断是否有空余
		if(course.getNumber() == course.getFillNumber()) {
			System.out.println("该课程报满！");
			CourseSelection(studentId);
		}
		Grades grades = new Grades();
		grades.setCourseId(courseId);
		grades.setNoId(studentId);
		GradesList.add(grades);
		System.out.println("选课成功！");
	}
	
	//学生课程查看
	public void StudentCourseSelect1(String studentId){
		int j = 1;
		for(int i=0;i<GradesList.size();i++) {
			if(GradesList.get(i).getNoId().equals(studentId)) {
				j++;
				System.out.println("序号          课程编号           课程名称            任课老师      ");
				System.out.println(j  + "     " +SelectCourseOne(GradesList.get(i).getCourseId()).getCourseId() + "     " + SelectCourseOne(GradesList.get(i).getCourseId()).getCourseName() + "     " + selectTeacherOne(SelectCourseOne(GradesList.get(i).getCourseId()).getTeacherId()).getName());
			}
		}
		StudentView(studentId);
	}
	
	//成绩查看
	public void StudentGradesSelect1(String studentId){
		int j = 1;
		for(int i=0;i<GradesList.size();i++) {
			if(GradesList.get(i).getNoId().equals(studentId) && GradesList.get(i).getGrades() != null) {
				j++;
				System.out.println("序号               课程名称            成绩      ");
				System.out.println(j  + "     "  + SelectCourseOne(GradesList.get(i).getCourseId()).getCourseName() + "     " + GradesList.get(i).getGrades());
			}
		}
		StudentView(studentId);
	}
	
	//修改学生密码
	public void StudentPasswordUpadate(String studentId) {
		System.out.println("请输入旧密码:");
		String oldPassword = input.next();
		Student student1 = selectStudentOne(studentId);
		if(student1 == null) {
			System.out.println("教师编号不存在！");
			StudentPasswordUpadate(studentId);
		}
		if(student1.getPassword().equals(oldPassword)) {
			System.out.println("旧密码错误！");
			StudentPasswordUpadate(studentId);
		}
		System.out.println("请输入新密码:");
		String newPassword = input.next();
		System.out.println("请输入新密码:");
		String newPassword2 = input.next();
		if(newPassword.equals(newPassword2)) {
			for(int i=0;i<StudentList.size();i++) {
				if(StudentList.get(i).getNoId().equals(studentId)) {
					StudentList.get(i).setPassword(newPassword);
					System.out.println("密码修改成功!");
					StudentView(studentId);
				}
			}
		}else {
			System.out.println("两次密码输入不一致！");
			StudentPasswordUpadate(studentId);
		}
		
	}
	
	//查询单独管理员接口
	public Admin selectAdminOne(String id) {
		for(Admin item : AdminList) {
			if(item.getNoId().equals(id)) {
				return item;
			}
		}
		return null;
	}
	
	//管理员信息展示
	public void AdminSelectAll(){
		for(int i=0;i<AdminList.size();i++) {
			System.out.println("序号          职工号            名称                密码");
			System.out.println(i+1  + "     " +AdminList.get(i).getNoId() + "     " + AdminList.get(i).getName() + "     " +AdminList.get(i).getPassword());
		}
		AdminManage();
	}
	
	//管理员添加
	public void AdminAdd(){
		Admin admin = new Admin();
		System.out.println("请输入员工号:");
		String noId = input.next();
		//判断员工号是否存在
		Admin admin1 = selectAdminOne(noId);
		if(admin1 != null) {
			System.out.println("员工编号已存在！");
			AdminAdd();
		}
		System.out.println("请输入姓名:");
		String name = input.next();
		System.out.println("请输入密码:");
		String password = input.next();
		admin.setNoId(noId);
		admin.setName(name);
		admin.setPassword(password);
		AdminList.add(admin);
		System.out.println("添加成功!");
		AdminManage();
	}
	
	//管理员删除
	public void AdminDeleted(){
		System.out.println("请输入员工号");
		String noId = input.next();
		//判断员工号是否存在
		Admin admin1 = selectAdminOne(noId);
		if(admin1 == null) {
			System.out.println("员工编号不存在！");
			AdminDeleted();
		}
		for(int i=0;i<AdminList.size();i++) {
			if(AdminList.get(i).getNoId().equals(noId)) {
				AdminList.remove(i);
				System.out.println("删除成功!");
				AdminManage();
			}
		}
	
	}
	//管理员修改
	public void AdminUpdate(){
		System.out.println("请输入员工号");
		String noId = input.next();
		//判断员工号是否存在
		Admin admin1 = selectAdminOne(noId);
		if(admin1 == null) {
			System.out.println("员工编号不存在！");
			AdminUpdate();
		}
		System.out.println("请输入姓名:");
		String name = input.next();
		System.out.println("请输入密码:");
		String password = input.next();
		for(int i=0;i<AdminList.size();i++) {
			if(AdminList.get(i).getNoId().equals(noId)) {
				AdminList.get(i).setName(name);
				AdminList.get(i).setPassword(password);
				System.out.println("修改成功!");
				AdminManage();
			}
		}
	}
	

	
	//查询单独教师接口
	public Teacher selectTeacherOne(String id) {
		for(Teacher item : TeacherList) {
			if(item.getTeacherId().equals(id)) {
				return item;
			}
		}
		return null;
	}
	
    //添加教师接口
	public void TeacherAdd() {
		Teacher teacher = new Teacher();
		System.out.println("请输入教师编号:");
		String teacherId = input.next();
		//判断员工号是否存在
		Teacher teacher1 = selectTeacherOne(teacherId);
		if(teacher1 != null) {
			System.out.println("教师编号已存在！");
			TeacherAdd();
		}
		System.out.println("请输入姓名:");
		String name = input.next();
		System.out.println("请输入密码:");
		String password = input.next();
		teacher.setTeacherId(teacherId);
		teacher.setName(name);
		teacher.setPassword(password);
		TeacherList.add(teacher);
		System.out.println("添加成功!");
		TeacherManage();
	}
	
	//修改教师信息接口
    public void TeacherUpdate() {
		System.out.println("请输入教师编号:");
		String teacherId = input.next();
		//判断员工号是否存在
		Teacher teacher1 = selectTeacherOne(teacherId);
		if(teacher1 == null) {
			System.out.println("教师编号不存在！");
			TeacherUpdate();
		}
		System.out.println("请输入姓名:");
		String name = input.next();
		System.out.println("请输入密码:");
		String password = input.next();
		for(int i=0;i<TeacherList.size();i++) {
			if(TeacherList.get(i).getTeacherId().equals(teacherId)) {
				TeacherList.get(i).setName(name);
				TeacherList.get(i).setPassword(password);
				System.out.println("修改成功!");
				TeacherManage();
			}
		}
	} 
	
	//删除教师信息接口
    public void TeacherDeleted() {
		System.out.println("请输入教师编号");
		String teacherId = input.next();
		//判断工号是否存在
		Teacher teacher1 = selectTeacherOne(teacherId);
		if(teacher1 == null) {
			System.out.println("教师编号不存在！");
			TeacherDeleted();
		}
		for(int i=0;i<TeacherList.size();i++) {
			if(TeacherList.get(i).getTeacherId().equals(teacherId)) {
				TeacherList.remove(i);
				System.out.println("删除成功!");
				TeacherManage();
			}
		}
	}
	
	//查询教师信息接口
    public void TeacherSelectAll() {
    	for(int i=0;i<TeacherList.size();i++) {
			System.out.println("序号          教师号            名称                密码");
			System.out.println(i+1  + "     " +TeacherList.get(i).getTeacherId() + "     " + TeacherList.get(i).getName() + "     " +TeacherList.get(i).getPassword());
		}
		TeacherManage();
	}
    
	 
	//查询单独学生接口
	public Student selectStudentOne(String id) {
		for(Student item : StudentList) {
			if(item.getNoId().equals(id)) {
				return item;
			}
		}
		return null;
	}
	
    //添加学生接口
	public void StudentAdd() {
		Student student = new Student();
		System.out.println("请输入学生编号:");
		String noId = input.next();
		//判断员工号是否存在
		Student student1 = selectStudentOne(noId);
		if(student1 != null) {
			System.out.println("教师编号已存在！");
			StudentAdd();
		}
		System.out.println("请输入姓名:");
		String name = input.next();
		System.out.println("请输入密码:");
		String password = input.next();
		student.setNoId(noId);
		student.setName(name);
		student.setPassword(password);
		StudentList.add(student);
		System.out.println("添加成功!");
		StudentManage();
	}
	
	//修改学生信息接口
    public void StudentUpdate() {
		System.out.println("请输入学号:");
		String noId = input.next();
		//判断员工号是否存在
		Student student1 = selectStudentOne(noId);
		if(student1 == null) {
			System.out.println("学号不存在！");
			StudentUpdate();
		}
		System.out.println("请输入姓名:");
		String name = input.next();
		System.out.println("请输入密码:");
		String password = input.next();
		for(int i=0;i<StudentList.size();i++) {
			if(StudentList.get(i).getNoId().equals(noId)) {
				StudentList.get(i).setName(name);
				StudentList.get(i).setPassword(password);
				System.out.println("修改成功!");
				StudentManage();
			}
		}
	
	} 
	
	//删除学生信息接口
    public void StudentDeleted() {
		System.out.println("请输入学生编号");
		String noId = input.next();
		//判断工号是否存在
		Student student1 = selectStudentOne(noId);
		if(student1 == null) {
			System.out.println("学号不存在！");
			StudentDeleted();
		}
		for(int i=0;i<StudentList.size();i++) {
			if(StudentList.get(i).getNoId().equals(noId)) {
				StudentList.remove(i);
				System.out.println("删除成功!");
				StudentManage();
			}
		}
	
	}
	
    //学生信息展示
    public void StudentSelectAll() {
    	for(int i=0;i<StudentList.size();i++) {
			System.out.println("序号          学生号            名称                密码");
			System.out.println(i+1  + "     " +StudentList.get(i).getNoId() + "     " + StudentList.get(i).getName() + "     " +StudentList.get(i).getPassword());
		}
		StudentManage();
	}

	
	//获取单独课程
	 private Course SelectCourseOne(String id) {
			// TODO Auto-generated method stub
			for(Course item : CourseList) {
				if(item.getCourseId().equals(id)) {
					return item;
				}
			}
			return null;
		}
	
	//课程添加
	 public void CourseAdd(){
		 Course course = new Course();
		 System.out.println("请输入课程编号");
		 String courseId = input.next();
		 Course course1 = SelectCourseOne(courseId);
		 if(course1 != null) {
			 System.out.println("课程编号已存在!");
			 CourseAdd();
		 }
		 System.out.println("请输入课程名称");
		 String courseName = input.next();
		 System.out.println("请输入任课教师");
		 String teacherId = input.next();
		 System.out.println("请输入课程人数");
		 int number = input.nextInt();
		 course.setCourseId(courseId);
		 course.setCourseName(courseName);
		 course.setNumber(number);
		 course.setFillNumber(0);
		 course.setTeacherId(teacherId);
		 CourseList.add(course);
		 System.out.println("添加成功!");
		 System.out.println(CourseList.size());
		 CourseManage();
	 }
	 
	
	//课程修改
	 public void CourseUpdate(){
		 System.out.println("请输入课程编号");
		 String courseId = input.next();
		 Course course1 = SelectCourseOne(courseId);
		 if(course1 == null) {
			 System.out.println("课程编号不存在!");
			 CourseUpdate();
		 }
		 System.out.println("请输入课程名称");
		 String courseName = input.next();
		 System.out.println("请输入任课教师");
		 String teacherId = input.next();
		 Teacher teacher = selectTeacherOne(teacherId);
		 if(teacher == null){
			 System.out.println("教师编号不存在！");
			 CourseUpdate();
		 }
		 System.out.println("请输入课程人数");
		 int number = input.nextInt();
			for(int i=0;i<CourseList.size();i++) {
				if(CourseList.get(i).getCourseId().equals(courseId)) {
					CourseList.get(i).setCourseName(courseName);
					CourseList.get(i).setNumber(number);
					CourseList.get(i).setTeacherId(teacherId);
					System.out.println("修改成功!");
					CourseManage();
				}
			}
			}

	 //课程删除
	public void CourseDeleted(){
		 System.out.println("请输入课程编号");
		 String courseId = input.next();
		 Course course1 = SelectCourseOne(courseId);
		 if(course1 == null) {
			 System.out.println("课程编号不存在!");
			 CourseDeleted();
		 }
			for(int i=0;i<CourseList.size();i++) {
				if(CourseList.get(i).getCourseId().equals(courseId)) {
					CourseList.remove(i);
					System.out.println("删除成功!");
					CourseManage();
				}
			}
	}

	 //课程查看
	public void CourseSelectAll(){
		for(int i=0;i<CourseList.size();i++) {
			System.out.println("序号          课程编号           课程名称            任课老师        课程人数              报名人数");
			System.out.println(i+1  + "     " +CourseList.get(i).getCourseId() + "     " + CourseList.get(i).getCourseName() + "     " + selectTeacherOne(CourseList.get(i).getTeacherId()).getName() + "         "  + CourseList.get(i).getNumber() + "         "  + CourseList.get(i).getFillNumber());
		}
		CourseManage();
	}
	
    
    
	//查询单独成绩接口
	public Grades selectGradesOne(String id,String courseId) {
		for(Grades item : GradesList) {
			if(item.getNoId().equals(id)&&item.getCourseId().equals(courseId)) {
				return item;
			}
		}
		return null;
	}
	
	
	//查询单独课程接口
	public Course selectCourseOne(String id) {
		for(Course item : CourseList) {
			if(item.getCourseId().equals(id)) {
				return item;
			}
		}
		return null;
	}
	

    public static void clear() {  
//        for (int i = 0; i < 5; i++) {  
//            System.out.println();  
//        }  
    }  
	
}
